class Solution {
public:
    int maximumEnergy(vector<int>& energy, int k) {
        int ret = -2000, n = energy.size();

        for (int i = n - k; i < n; i++) {
            int tmp = 0;
            for (int j = i; j >= 0; j -= k) {
                tmp += energy[j];
                ret = max(ret, tmp);
            }
        }
        return ret;
    }
};